package jsqlite;

import java.io.IOException;
import java.io.InputStream;

/* compiled from: Blob.java */
/* loaded from: classes2.dex */
class BlobR extends InputStream {
    private Blob blob;
    private int pos = 0;

    @Override // java.io.InputStream
    public void mark(int i) {
    }

    @Override // java.io.InputStream
    public boolean markSupported() {
        return false;
    }

    @Override // java.io.InputStream
    public void reset() throws IOException {
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public BlobR(Blob blob) {
        this.blob = blob;
    }

    @Override // java.io.InputStream
    public int available() throws IOException {
        int i = this.blob.size - this.pos;
        if (i < 0) {
            return 0;
        }
        return i;
    }

    @Override // java.io.InputStream, java.io.Closeable, java.lang.AutoCloseable
    public void close() throws IOException {
        this.blob.close();
        this.blob = null;
        this.pos = 0;
    }

    @Override // java.io.InputStream
    public long skip(long j) throws IOException {
        long j2 = this.pos + j;
        if (j2 < 0) {
            this.pos = 0;
            return 0L;
        } else if (j2 > this.blob.size) {
            long j3 = this.blob.size;
            this.pos = this.blob.size;
            return j3;
        } else {
            this.pos = (int) j2;
            return j2;
        }
    }

    @Override // java.io.InputStream
    public int read() throws IOException {
        byte[] bArr = new byte[1];
        int read = this.blob.read(bArr, 0, this.pos, 1);
        if (read > 0) {
            this.pos += read;
            return bArr[0];
        }
        return -1;
    }

    @Override // java.io.InputStream
    public int read(byte[] bArr) throws IOException {
        int read = this.blob.read(bArr, 0, this.pos, bArr.length);
        if (read > 0) {
            this.pos += read;
            return read;
        }
        return -1;
    }

    @Override // java.io.InputStream
    public int read(byte[] bArr, int i, int i2) throws IOException {
        if (i + i2 > bArr.length) {
            i2 = bArr.length - i;
        }
        if (i2 < 0) {
            return -1;
        }
        if (i2 == 0) {
            return 0;
        }
        int read = this.blob.read(bArr, i, this.pos, i2);
        if (read > 0) {
            this.pos += read;
            return read;
        }
        return -1;
    }
}
